Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply modal pattern to search box pop-up #1932

Merged
merged 8 commits into from
Jul 25, 2024

Conversation

gabalafou
Copy link
Collaborator

@gabalafou gabalafou commented Jul 17, 2024

Closes external issue Quansight-Labs/czi-scientific-python-mgmt#83.

Summary

This PR implements the pop-up search field as an HTML-native <dialog>. This somewhat simplifies our implementation and brings accessibility affordances with it.

I also introduced a couple visual changes, which fix #1714.

Before

Before this PR, there is a border around the input element and its parent, so you have two borders that bump against each other on the top, bottom, and right sides. Before this PR, the focus ring was just around the input element when it was focus, not the entire search bar.

After

This PR removes the border around the input element, so that there is only one border, around the parent element, which is the same as around the entire search bar. This PR puts the focus ring around the entire search bar when the input element is focused rather than just around the input element itself. To my eyes this looks more natural.

Test plan

I tested this in Firefox, Chrome, and Safari on my Mac. I also tested it in Ubuntu + Firefox.

TODO:

  • Test on Windows

There are at least six different presentations of the search input field that need to be tested:

  1. Search modal on homepage
  2. Search input box on search results page
  3. Persistent search field at /examples/persistent-search-field.html
  4. Mobile: search modal on homepage
  5. Mobile: search input box on search results page
  6. BROKEN. Mobile: persistent search field

As the persistent search is currently broken in production, it's also broken in this PR. How so? On the persistent search field example page, if you click the search button in the nav bar, or you press the keyboard shortcut (Ctrl + K), neither of those actions does anything because the "persistent" search field is hidden behind the mobile sidebar which only opens up if you click the hamburger icon.

Copy link
Collaborator Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

<div class="search-button__overlay"></div>
<div class="search-button__search-container">{% include "../components/search-field.html" %}</div>
</div>
<dialog class="search-button__search-container">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this class should be renamed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question in another comments if this should even be made an id, as the js assume there is only one I think. Don't trust me on Js.

input.focus();
input.select();
input.scrollIntoView({ block: "center" });
// if the input field is not the hidden one, then toggle its focus state
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the left side, the logic in this else-branch was always run. That was because the old way of opening the search pop-up did not automatically focus the search input field. However, when the search input field is inside a dialog, then when you open the dialog, it is automatically focussed. So if you then run the code below, you get a buggy sequence of actions:

  1. Call to searchDialog.showModal() puts focus on search input field
  2. Call to input.blur() removes focus from search input field

So the solution is to put this toggle logic in an else-branch to handle the case when the search field is on already on the page (for example, the search results page, or a page with a persistent search bar).

if (overlay) {
overlay.onclick = toggleSearchField;
}
// If user clicks outside the search modal dialog, then close it.
Copy link
Collaborator Author

@gabalafou gabalafou Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behavior for modal dialogs is to stay on the screen even if you click on the dialog's backdrop.

To me the old behavior seemed natural though - i.e., if the user clicks the backdrop, we remove the pop-up search bar. So I restore that behavior here.

color: var(--pst-color-border);
}
}

.form-control {
Copy link
Collaborator Author

@gabalafou gabalafou Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged these rules in with the input selector above. As far as I can tell, I searched the code base, and the only place I could find this class being used is on the input element in the search-field.html component.

}

// Shows off the keyboard shortcuts for the button
.search-button__kbd-shortcut {
display: flex;
position: absolute;
Copy link
Collaborator Author

@gabalafou gabalafou Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think position: absolute was actually a bad idea because it allows the search terms in the input box to bleed into the span displaying the keyboard shortcut (think narrow screen rather than super long search string).

Comment on lines -110 to -111
padding-top: 0;
padding-bottom: 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These padding rules are not needed. The form already has 0 top and bottom padding.

Copy link
Collaborator Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

@@ -6,7 +6,6 @@
<input type="search"
class="form-control"
name="q"
id="search-input"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's misleading to put an id on this element because this template can currently be rendered on the same page more than once. This definitely happens in the PST docs, for example, on the search results page.

@choldgraf
Copy link
Collaborator

this has been bugging me for so long, it looks much nicer thanks

@gabalafou
Copy link
Collaborator Author

gabalafou commented Jul 18, 2024

I started a discussion about how I would like to change the keyboard shortcut behavior.

Copy link

Coverage report

This PR does not seem to contain any modification to coverable code.

@Carreau Carreau merged commit 72a756d into pydata:main Jul 25, 2024
29 checks passed
@gabalafou gabalafou deleted the fix-search-modal branch July 25, 2024 15:59
Carreau added a commit that referenced this pull request Aug 29, 2024
This is very similar to #1932.

Closes external issue
Quansight-Labs/czi-scientific-python-mgmt#84

---------

Co-authored-by: M Bussonnier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine active search field design
3 participants